﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lyh.API.Feixin;

namespace Lyh.Test.WindowsFormsApplication
{
    public partial class FeixinTestForm : Form
    {
        private WebMessenger wm = new WebMessenger();
        public FeixinTestForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var info = wm.GetPersonalInfo();
            MessageBox.Show(info.rv.uid.ToString());
            if (info.rc != 200) return;

            var cinfo = wm.GetConnectInfo();
            MessageBox.Show(cinfo.rv.Count.ToString());
            if (info.rc != 200) return;

            var it = cinfo.rv.SingleOrDefault(m => m.Data.mn == txtToTel.Text.Trim());

            var to = info.rv.uid.ToString();
            if (it != null) to += "," + it.Data.uid;

            var sr = wm.Send(info.rv.uid.ToString(), to, txtMsg.Text);
            MessageBox.Show(sr.rc.ToString());
        }

        private void FeixinTestForm_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = wm.GetPic();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = wm.GetPic();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            var result = wm.Login(txtTel.Text, txtPwd.Text, txtCode.Text);
            MessageBox.Show(result.rc.ToString());
        }
    }
}
